package com.wnxy.sk.order.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wnxy.sk.common.result.Result;
import com.wnxy.sk.common.result.enums.impl.ResultCode;
import com.wnxy.sk.order.dto.OrderDto;
import com.wnxy.sk.order.entity.Order;
import com.wnxy.sk.order.service.IOrderService;
import com.wnxy.sk.order.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Jet
 * @since 2022-10-17
 */
@RestController
@RequestMapping("/auth/order")
@Api(tags = "订单模块")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @PostMapping
    @ApiOperation("生成订单")
    public Result createOrder(@RequestBody OrderDto orderDto) {
        String orderSn = orderService.createOrder(orderDto);
        return Result.ok(orderSn);
    }

    @GetMapping("/{orderSn}")
    @ApiOperation("根据订单编号查询")
    public Result<OrderVo> getOrderBySn(@PathVariable("orderSn") String orderSn) {
        OrderVo vo = orderService.getOrderBySn(orderSn);
        return Result.ok(vo);
    }

    @PutMapping("/{orderSn}")
    @ApiOperation("更新订单状态")
    public Result update(@PathVariable("orderSn") String orderSn){
        Integer status = orderService.updateByOrderSn(orderSn);
        return Result.ok(status);
    }

}

